package com.zking.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpSession;

@Controller
public class MyController2 {
    @RequestMapping("/page")
    public String page(Model model) {
        return "page";
    }
    
    @RequestMapping("/login")
    public String test1(Model model, HttpSession session, RedirectAttributes attributes) {
        session.setAttribute("user", "老王");
        attributes.addFlashAttribute("info", "登录成功");
        return "redirect:/page";
    }
    
    @RequestMapping("/logout")
    public String test2(Model model, HttpSession session, RedirectAttributes attributes) {
        session.invalidate();
        attributes.addFlashAttribute("info", "你已经退出");
        return "redirect:/page";
    }
}
